package com.sun.service.ums.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.pojo.UmsResource;
import com.sun.mapper.ums.UmsResourceMapper;
import com.sun.service.ums.IUmsResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台资源表 服务实现类
 * </p>
 *
 * @author 妙妙屋
 * @since 2021-12-16
 */
@Service
public class UmsResourceServiceImpl extends ServiceImpl<UmsResourceMapper, UmsResource> implements IUmsResourceService {
    @Autowired
    private UmsResourceMapper umsResourceMapper;
    @Override
    public IPage<UmsResource> selectPage(Long categoryId, String nameKeyword, Long pageNum, Long pageSize, String urlKeyword) {
        Page<UmsResource> page = new Page<>(pageNum, pageSize);
        QueryWrapper<UmsResource> wrapper = new QueryWrapper<>();
        //设置条件
        if(categoryId != null){
            wrapper.eq("category_id",categoryId);
        }
        if(StringUtils.isNotBlank(nameKeyword)){
            wrapper.like("name",nameKeyword);
        }
        if(StringUtils.isNotBlank(urlKeyword)){
            wrapper.like("url",urlKeyword);
        }

        return umsResourceMapper.selectPage(page,wrapper);
    }
}
